# !/usr/bin/env python
# encoding: utf-8
# @File    : process_data_module.py
# @Time    : 2021/2/13
# @Author  : qiaowei
# @Version : 1.0
# @Email   : weiweiqiao@126.com
# @License : (C) Copyright 2013-2021
# @Brief   :


from PySide2.QtCore import QThread
from PySide2.QtCore import QObject
from PySide2.QtCore import QFile
from PySide2.QtCore import QTextStream
from PySide2.QtCore import QIODevice
from PySide2.QtCore import Slot
from data_module.track_data_integrated_module import TrackData


class FileDataProcessing(QObject):
    def __init__(self):
        super(FileDataProcessing, self).__init__()

    @Slot(list)
    def split_data_to_different_file(self, files_name_with_path: list):
        """
        根据传入的文件名列表，依次读取文件内容，将读取到的数据项用信号发射

        :param files_name_with_path: 文件名列表
        :return: None
        """
        print(id(QThread.currentThread()))
        for file_name in files_name_with_path:
            file = QFile(file_name)

            if not file.open(QIODevice.ReadOnly | QIODevice.Text):
                return

            in_stream = QTextStream(file)
            in_stream.setCodec('utf-8')
            track_data_integrated = None
            while not in_stream.atEnd():
                track_data_integrated = TrackData()
                track_data_integrated.setup_track_data(file.readLine())
